** INDIVIDUAL BREAKS E5

* pccount 
clear
import excel "$P_Data_Processed/structural_breaks_pccount_e5.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pccount_breaks_e5.dta", replace 

* pcresponse 
clear
import excel "$P_Data_Processed/structural_breaks_pcresponse_e5.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pcresponse_breaks_e5.dta", replace 

* oil 
clear
import excel "$P_Data_Processed/structural_breaks_oil_e5.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/oil_breaks_e5.dta", replace 

* weather 
clear
import excel "$P_Data_Processed/structural_breaks_weather_e5.xlsx", firstrow clear
keep if P<0.01
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/weather_breaks_e5.dta", replace 


*** COMBINATIONS 

* pccount + pcresponse
clear
use "$P_Data_Processed/pccount_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_pcresponse_4week_e5.dta", replace

* pccount + oil
clear
use "$P_Data_Processed/pccount_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_oil_4week_e5.dta", replace

* pcresponse + oil  
clear
use "$P_Data_Processed/pcresponse_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pcresponse_oil_4week_e5.dta", replace

* weather + oil
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_oil_4week_e5.dta", replace

* weather + pccount 
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pccount_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pccount_4week_e5.dta", replace

* weather + pcresponse 
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pcresponse_4week_e5.dta", replace

*** FINAL COMBINATION  - ALL STATIONS WITH AT LEAST 2/4 BREAKS 

clear
use "$P_Data_Processed/weather_pcresponse_4week_e5.dta"
keep StID avgdate
append using "$P_Data_Processed/weather_pccount_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/weather_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pcresponse_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/adopter_measures_4week_e5.dta", replace

clear


** INDIVIDUAL BREAKS E10

* pccount 
clear
import excel "$P_Data_Processed/structural_breaks_pccount_e10.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pccount_breaks_e10.dta", replace 

* pcresponse 
clear
import excel "$P_Data_Processed/structural_breaks_pcresponse_e10.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pcresponse_breaks_e10.dta", replace 

* oil 
clear
import excel "$P_Data_Processed/structural_breaks_oil_e10.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/oil_breaks_e10.dta", replace 

* weather 
clear
import excel "$P_Data_Processed/structural_breaks_weather_e10.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/weather_breaks_e10.dta", replace 


*** COMBINATIONS 

* pccount + pcresponse
clear
use "$P_Data_Processed/pccount_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_pcresponse_4week_e10.dta", replace

* pccount + oil
clear
use "$P_Data_Processed/pccount_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_oil_4week_e10.dta", replace

* pcresponse + oil  
clear
use "$P_Data_Processed/pcresponse_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pcresponse_oil_4week_e10.dta", replace

* weather + oil
clear
use "$P_Data_Processed/weather_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_oil_4week_e10.dta", replace

* weather + pccount 
clear
use "$P_Data_Processed/weather_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pccount_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pccount_4week_e10.dta", replace

* weather + pcresponse 
clear
use "$P_Data_Processed/weather_breaks_e10.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e10.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pcresponse_4week_e10.dta", replace

*** FINAL COMBINATION  - ALL STATIONS WITH AT LEAST 2/4 BREAKS 

clear
use "$P_Data_Processed/weather_pcresponse_4week_e10.dta"
keep StID avgdate
append using "$P_Data_Processed/weather_pccount_4week_e10.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_oil_4week_e10.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/weather_oil_4week_e10.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_4week_e10.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pcresponse_oil_4week_e10.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/adopter_measures_4week_e10.dta", replace

clear

** INDIVIDUAL BREAKS diesel

* pccount 
clear
import excel "$P_Data_Processed/structural_breaks_pccount_diesel.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pccount_breaks_diesel.dta", replace 

* pcresponse 
clear
import excel "$P_Data_Processed/structural_breaks_pcresponse_diesel.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/pcresponse_breaks_diesel.dta", replace 

* oil 
clear
import excel "$P_Data_Processed/structural_breaks_oil_diesel.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/oil_breaks_diesel.dta", replace 

* weather 
clear
import excel "$P_Data_Processed/structural_breaks_weather_diesel.xlsx", firstrow clear
keep if P<0.05
drop if P==.
rename BD y2kW 
destring y2kW, replace 
replace StID = subinstr(StID,"_e5.dta","",.)
destring StID, replace
by StID, sort: keep if _n==1

merge m:1 y2kW using  "$P_Data_Processed/week_y2kW_concordance.dta"
drop if _merge==2
drop _merge

keep StID weekly_date 
rename weekly_date wdate 
format wdate %tw 

save "$P_Data_Processed/weather_breaks_diesel.dta", replace 


*** COMBINATIONS 

* pccount + pcresponse
clear
use "$P_Data_Processed/pccount_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_pcresponse_4week_diesel.dta", replace

* pccount + oil
clear
use "$P_Data_Processed/pccount_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_oil_4week_diesel.dta", replace

* pcresponse + oil  
clear
use "$P_Data_Processed/pcresponse_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pcresponse_oil_4week_diesel.dta", replace

* weather + oil
clear
use "$P_Data_Processed/weather_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_oil_4week_diesel.dta", replace

* weather + pccount 
clear
use "$P_Data_Processed/weather_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pccount_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pccount_4week_diesel.dta", replace

* weather + pcresponse 
clear
use "$P_Data_Processed/weather_breaks_diesel.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_diesel.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<5
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pcresponse_4week_diesel.dta", replace

*** FINAL COMBINATION  - ALL STATIONS WITH AT LEAST 2/4 BREAKS 

clear
use "$P_Data_Processed/weather_pcresponse_4week_diesel.dta"
keep StID avgdate
append using "$P_Data_Processed/weather_pccount_4week_diesel.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_oil_4week_diesel.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/weather_oil_4week_diesel.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_4week_diesel.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pcresponse_oil_4week_diesel.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/adopter_measures_4week_diesel.dta", replace

clear


** E5 alternative definitions 


*** 2 week COMBINATIONS 

* pccount + pcresponse
clear
use "$P_Data_Processed/pccount_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_pcresponse_2week_e5.dta", replace

* pccount + oil
clear
use "$P_Data_Processed/pccount_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pccount_oil_2week_e5.dta", replace

* pcresponse + oil  
clear
use "$P_Data_Processed/pcresponse_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/pcresponse_oil_2week_e5.dta", replace

* weather + oil
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/oil_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_oil_2week_e5.dta", replace

* weather + pccount 
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pccount_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pccount_2week_e5.dta", replace

* weather + pcresponse 
clear
use "$P_Data_Processed/weather_breaks_e5.dta"
rename wdate wdate1 
merge 1:1 StID using "$P_Data_Processed/pcresponse_breaks_e5.dta"
keep if _merge==3
drop _merge 
gen weekdist=abs(wdate-wdate1)
keep if weekdist<3
gen avgdate=round((wdate+wdate1)/2)
keep StID avgdate 
save "$P_Data_Processed/weather_pcresponse_2week_e5.dta", replace

*** FINAL COMBINATION  - ALL STATIONS WITH AT LEAST 2/4 BREAKS 

clear
use "$P_Data_Processed/weather_pcresponse_2week_e5.dta"
keep StID avgdate
append using "$P_Data_Processed/weather_pccount_2week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_oil_2week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/weather_oil_2week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_2week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pcresponse_oil_2week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/adopter_measures_2week_e5.dta", replace

clear




** 2 out of 3, no PCResponse_E5
clear
use "$P_Data_Processed/weather_pccount_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/weather_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/new_adopter_measures_2o3_noPCRes.dta", replace

** 2 out of 3, no No Oil 
clear
use "$P_Data_Processed/weather_pcresponse_4week_e5.dta"
keep StID avgdate
append using "$P_Data_Processed/weather_pccount_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/new_adopter_measures_2o3_noOil.dta", replace

** 2 out of 3, always PCCount 
clear
use "$P_Data_Processed/weather_pccount_4week_e5.dta"
keep StID avgdate
append using "$P_Data_Processed/pccoun_oil_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
append using "$P_Data_Processed/pccount_pcresponse_4week_e5.dta"
keep StID avgdate
sort StID avgdate
by StID: keep if _n==1
save  "$P_Data_Processed/new_adopter_measures_2o3_pccount_always.dta", replace

** e5 + diesel

clear
use "$P_Data_Processed/adopter_measures_4week_diesel.dta"
rename avgdate avgdate_diesel
merge 1:1 StID using "$P_Data_Processed/adopter_measures_4week_e5.dta"
keep if _merge==3
drop _merge
gener avgdate_diesel_rounded = round(avgdate_diesel)


gener avgdate_diff = abs(avgdate - avgdate_diesel_rounded)
keep if avgdate_diff<=4

gener new_avgdate = (avgdate + avgdate_diesel_rounded)/2
replace new_avgdate = round(new_avgdate)
keep StID new_avgdate
rename new_avgdate avgdate
save "$P_Data_Processed/new_adopter_measures_e5_diesel.dta", replace 

